export default (route) => {
  return {
    data() {
      return {
        scroll: 0
      }
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        const list = vm.$refs.list
        setTimeout(() => {
          list.scrollTop = vm.scroll
        }, 0)
      })
    },
    beforeRouteLeave(to, from, next) {
      const list = this.$refs.list
      if (route.includes(to.name)) {
        this.scroll = list.scrollTop
      } else {
        this.scroll = 0
      }
      next()
    }
  }
}
